<template>
  <el-dialog
    title="印章申请（企业）"
    :visible.sync="dialogVisibleCompany"
    width="534px"
    :before-close="handleClose"
    :show-close="true"
  >
    <div class="company-box">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="140px"
        class="demo-ruleForm"
      >
        <el-form-item label="公司名称：" prop="userName">
          <el-input
            v-model="ruleForm.userName"
            placeholder="请输入公司名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="单位类型：" prop="corpType">
          <el-select v-model="ruleForm.corpType" placeholder="请选择">
            <el-option
              v-for="item in unitOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="企业注册类型：" prop="corpRegisterType">
          <el-select v-model="ruleForm.corpRegisterType" placeholder="请选择"  @change="selectCorpRegisterType(ruleForm.corpRegisterType)">
            <el-option
              v-for="item in companyRegisterTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="labelCode" prop="certificateId">
          <el-input
            v-model="ruleForm.certificateId"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="prompts-one-footer dialog-footer">
      <el-button @click="dialogVisibleCompany = false">取 消</el-button>
      <el-button type="primary" @click="submitForm('ruleForm')"
        >申 请</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        corpRegisterType: "NORMAL",
        certificateId: "",
        companyName: "",
        corpType: "0",
      },
      rules: {
        corpRegisterType: [
          { required: true, message: "请选择企业注册类型", trigger: "change" },
        ],

        certificateId: [
          { required: true, message: "请输入", trigger: "blur" },
        ],
        userName: [
          { required: true, message: "请输入公司名称", trigger: "blur" },
        ],
        corpType: [
          { required: true, message: "请选择单位类型", trigger: "change" },
        ],
      },
      dialogVisibleCompany:false,
          unitOptions:[
         {
          value: "0",
          label: "普通企业",
        },
        {
          value: "1",
          label: "社会团体",
        },
         {
          value: "2",
          label: "事业单位",
        },
        {
          value: "3",
          label: "民办非企业单位",
        },
          {
          value: "4",
          label: "党政及国家机构",
        },
        
      ],
      labelCode:"组织机构代码号",
       companyRegisterTypeOptions:[
         {
          value: "NORMAL",
          label: "组织机构代码号",
        },
        {
          value: "MERGE",
          label: "多证合一",
        },
         {
          value: "REGCODE",
          label: "企业工商注册码及其他",
        }
        
      ],
    };
  },
  methods: {
       // 选择企业类型
    selectCorpRegisterType (val) {
      console.log(val)
      if (val=='MERGE') {
          this.labelCode='统一社会信用代码'
      } else if (val=='REGCODE') {
        this.labelCode='企业工商注册码及其他'
      } else  {
        this.labelCode='组织机构代码号'
      }
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
            this.$http("post",'/sys/esign/addCorpAccount.do',this.ruleForm).then(res=>{
              if (res.code =='0000') {
                this.$message({
                  type:'success',
                  message:"操作成功"
                })
                this.dialogVisibleCompany = false
                this.$emit('upDate')
              }
            })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    init () {
      this.dialogVisibleCompany = true
    },
      handleClose () {
      this.dialogVisibleCompany = false
        this.$emit('upDate')
    }
  },
};
</script>
<style >
.company-box .el-input__inner {
  background: #f6f6f6;
  width: 296px;
}
.company-box .el-input__icon {
  color: #ee781b;
}
.company-box .el-form-item__label {
  color: #272727;
}
.company-box .el-button--primary {
  width: 145px;
  height: 38px;
  background: #ee781b;
  border-radius: 2px;
  border: 0;
  margin-top: 10px;
}
.prompts-one-footer .el-button--primary {
  width: 65px;
  height: 32px;
  background: #ee781b;
  border-radius: 2px;
  border: 0;
  padding: 0;
}
.prompts-one-footer .el-button--default {
  width: 65px;
  height: 32px;
  background: #ffffff;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  padding: 0;
}
</style>